﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Driver;
using System.Configuration;
using MongoDB.Bson;
using System.Collections.Specialized;

namespace WanPiJie
{
	public class MongoCollections
	{
		/// <summary>
		/// Mongo服务器
		/// </summary>
		public readonly static MongoDatabase Wanpijie;
		private readonly static MongoServer server;
		private readonly static MongoCredentials credentials;

		/// <summary>
		/// 对Mongo数据操作层进行初始化操作
		/// </summary>
		static MongoCollections()
		{
			var mongoCollection = (NameValueCollection)ConfigurationManager.GetSection("mongo");
			string[] authString = mongoCollection["credentials"].Split(';');
			server = MongoServer.Create(mongoCollection["connectionString"]);
			credentials = new MongoCredentials(authString[0], authString[1]);
			Wanpijie = server.GetDatabase("wanpijie", credentials);
		}
	}
}
